import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';

class AppUtils {
  static Future<String> findLocalPath() async {
    // 因为Apple没有外置存储，所以第一步我们需要先对所在平台进行判断
    // 如果是android，使用getExternalStorageDirectory
    // 如果是iOS，使用getApplicationSupportDirectory
    final directory = Platform.isAndroid ? await getExternalStorageDirectory() : await getApplicationSupportDirectory();
    return directory!.path;
  }

  static Future<void> confirm({
    String? content = "",
    VoidCallback? confirmCallback,
    VoidCallback? cancelCallback,
  }) async {
    return showDialog(
      context: Get.context!,
      builder: (context) {
        return AlertDialog(
          title: Text("提示"),
          content: Text(content!),
          actions: <Widget>[
            TextButton(
              child: Text("取消"),
              onPressed: () {
                Navigator.pop(context);
                if (cancelCallback != null) {
                  cancelCallback();
                }
              },
            ),
            TextButton(
              child: Text("确定"),
              onPressed: () {
                Navigator.pop(context);
                if (confirmCallback != null) {
                  confirmCallback();
                }
              },
            ),
          ],
        );
      },
    );
  }
}
